import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import { Provider } from 'react-redux';
import store from './store';
import { AppContainer } from 'react-hot-loader';  // 包裹根节点，想要渲染的内容

const root = document.getElementById('root');
const render = Component => {
  ReactDOM.render(
    <AppContainer>
      <Provider store={store}>
        <Component />
      </Provider>
    </AppContainer>,
    root
  )
};

render(App);  // 初始化渲染

if (module.hot) {
  // 当热更新代码出现时，把app重新渲染
  module.hot.accept('./App', () => {
    const NextApp = require('./App').default;   //注意不同模块引入方式的区别
    render(NextApp);
  })
}

// ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
